<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="时间" :labelCol="{span:6}" :wrapperCol="{span:18}" prop="date">
              <g-year-picker
                placeholder="请选择时间"
                v-model="model.date"
              ></g-year-picker>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="培养方案类型" :labelCol="{span:7}" :wrapperCol="{span:17}" prop="rcpyfaClassess">
              <j-dict-select-tag type="list" v-model="model.rcpyfaClassess" dictCode="RCPYFA_CLASSESS" placeholder="请选择培养方案类型" @change="getTotalScore"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="总分" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="totalScore">
              <a-input v-model="model.totalScore" placeholder="总分" :disabled="true"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="培养方案名称" :labelCol="{span:2}" :wrapperCol="{span:22}" prop="projectName">
              <a-input v-model="model.projectName" placeholder="请输入培养方案名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="备注" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    <!-- 子表单区域 -->
    <member-list ref="memberListRef" v-model="memberListTable.dataSource" :project-info="model" :disabled="formDisabled" :loading="memberListTable.loading"></member-list>
  </a-spin>
</template>

<script>

import { FormTypes,getRefPromise,VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
import { GfxyMemberListMixin } from '@/mixins/GfxyMemberListMixin'

import moment from 'moment'
import GYearPicker from '@views/gfxy/common/GYearPicker'
import MemberList from '@views/gfxy/common/memberList'
import { getAction } from '@api/manage'

export default {
  name: 'RcpyfaForm',
  mixins: [GfxyMemberListMixin],
  components: {GYearPicker,MemberList} ,
  data() {
    return {
      labelCol: {
        xs: { span: 12 },
        sm: { span: 12 },
      },
      wrapperCol: {
        xs: { span: 12 },
        sm: { span: 12 },
      },
      labelCol2: {
        xs: { span: 12 },
        sm: { span: 3 },
      },
      wrapperCol2: {
        xs: { span: 12 },
        sm: { span: 20 },
      },
      validatorRules: {
        date: [
          { required: true, message: '请输入时间!'},
        ],
        rcpyfaClassess: [
          { required: true, message: '请输入培养方案!'},
        ],
        projectName: [
          { required: true, message: '请输入专业!'},
        ],
      },
      url: {
        add: "/teaching/rcpyfa/add",
        edit: "/teaching/rcpyfa/edit",
        queryById: "/teaching/rcpyfa/queryById",
        getTotalScore: "teaching/rcpyfa/getTotalScore",
        memberList: {
          list: '/teaching/rcpyfa/queryMemberListByMainId'
        },
      }
    }
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    itemValue:{
      type: Number,
      required: true,
    },
    date:{
      type: String,
      required: true,
    }
  },
  computed: {
    formDisabled(){
      return this.disabled
    },
  },
  created () {
  },
  methods: {
    getTotalScore(){
      if(this.model.rcpyfaClassess != undefined){
        this.confirmLoading = true;
        getAction(this.url.getTotalScore,{}).then((res) => {
          if (res.success) {
            this.model.totalScore = res.result;
            this.$nextTick(()=>{
              this.$refs.memberListRef.getScore();
            })
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.confirmLoading = false;
        })
      }
    }
  }
}
</script>

<style scoped>
</style>